{layout name="layout" /}

<style>
    a.category,
    a.category:visited {
        color: darkgrey;
    }

    a.category:hover {
        color: blueviolet;

    }

    a.top {
        font-size: 18px;
    }

    li.son {
        margin-left: 20px;
    }

    li.grandson {
        margin-left: 40px;
    }

    .table td a {
        text-decoration: none;
    }

    #search .select-box {
        display: inline;
    }

    #search .select-box select {
        border: none;
    }
</style>

<div class="Hui-article">
    <div class="pos-a" style="width:150px;left:0;top:0; bottom:0; height:100%; border-right:1px solid #e5e5e5; background-color:#f5f5f5">
        <!-- 选择栏目浏览 -->
        <dl id="select-menu-article">
            <dt style="margin-top: 20px; margin-left: 20px;height:40px;font-size:20px;">
                <a href="{:url('index')}" class="btn btn-primary radius" {eq name='cid' value='' }style="background:#999;" {/eq}>所有文章</a>
            </dt>
            <dd>
                <button class="btn btn-primary radius" onclick="load_all()" title="点击展开,再次点击收回">展开栏目</button>
            </dd>
            <dd>
                <ul>
                    {foreach $data_category as $value}
                    <li>
                        <label>
                            <a href="javascript:void(0);" class="category top" data-cid="{$value.id}" data-status="0">
                                <i class="Hui-iconfont cate_icon">&#xe698;</i>
                            </a>
                        </label>
                        <a href="{:url('index','cid='.$value.id)}" title="{$value.name}" {eq name='cid' value='$value.id' }style="background:#999;"
                            {/eq}>{$value.name}</a>
                    </li>
                    {notempty name="value.child"}{foreach $value.child as $val}
                    <li class="son level_{$value.id}" style="display:none;">
                        <label>
                            <a href="javascript:void(0);" class="category" data-cid="{$val.id}" data-status="0">
                                <i class="Hui-iconfont cate_icon">&#xe698;</i>
                            </a>
                        </label>
                        <a href="{:url('index','cid='.$val.id)}" title="{$val.name}" {eq name='cid' value='$val.id' }style="background:#999;" {/eq}>{$val.name}</a>
                    </li>
                    {notempty name="val.child"}{foreach $val.child as $vo}
                    <li class="grandson level_{$val.id} top_{$value.id}" style="display:none;" data-status="0">
                        <a href="{:url('index','cid='.$vo.id)}" class="" title="{$vo.name}" {eq name='cid' value='$vo.id' }style="background:#999;"
                            {/eq}>{$vo.name}</a>
                    </li>
                    {/foreach}{/notempty} {/foreach}{/notempty} {/foreach}
                    <li style="margin-left: 20px;height:30px;">
                        <a href="{:url('index','cid=0')}" {eq name='cid' value='0' }style="background:#999;" {/eq} title="其他栏目">其他</a>
                    </li>
                </ul>
            </dd>
        </dl>
    </div>
    <div style="margin-left:150px;">
        <div class="pd-20">
            <div class="text-c" style="margin-right: 10%;">
                <form action="" method="GET" id='search'>
                    <a href="{:url('index')}" class="btn btn-danger">清除条件</a>
                    日期范围：

                    <input type="date" id="logmin" class="input-text Wdate" style="width:150px;">
                    -
                    <input type="date" id="logmax" class="input-text Wdate" style="width:150px;">
                    <span>置顶:</span>
                    <span class="select-box">
                        <select id="top" name="top">
                            <option value="0">--全部--</option>
                            <option value="1">--置顶--</option>
                            <option value="2">--非置顶--</option>
                        </select>
                    </span>
                    <span>状态:</span>
                    <span class="select-box">
                        <select id="status" name="status">
                            <option value="0">--全部--</option>
                            <option value="1">--正常--</option>
                            <option value="2">--下线--</option>
                        </select>
                    </span>
                    <span>审核:</span>
                    <span class="select-box">
                        <select id="post" name="post">
                            <option value="0">--全部--</option>
                            <option value="1">--已通过--</option>
                            <option value="2">--已驳回--</option>
                        </select>
                    </span>
                    <input type="text" name="search" id="search" value="{notempty name='search'}{$search}{/notempty}" placeholder=" 文章名称" style="width:250px"
                        class="input-text">
                    <button name="" id="" class="btn btn-success" type="submit">
                        <i class="Hui-iconfont">&#xe665;</i> 搜文章</button>
                </form>
            </div>
            <div class="cl pd-5 bg-1 bk-gray mt-20">
                <span class="l">
                    <a href="javascript:;" onclick="del_all('article')" class="btn btn-danger radius">
                        <i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>
                    <a href="{:url('article/add', 'cid='.$cid)}" class="btn btn-primary radius">
                        <i class="Hui-iconfont">&#xe600;</i>添加文章</a>
                </span>
            </div>
            <div class="cl pd-5 bg-1 bk-gray">
                <span class="r">
                    <a href="javascript:;" onclick="duty_all_pass()" class="btn btn-success radius">
                        <i class="Hui-iconfont">&#xe6e1;</i> 审核批量通过</a>
                    <a href="javascript:;" onclick="duty_all_reject()" class="btn btn-danger radius">
                        <i class="Hui-iconfont">&#xe6dd;</i> 审核批量驳回</a>
                    <a href="javascript:;" onclick="duty_all_top_up()" class="btn btn-success radius">
                        <i class="Hui-iconfont">&#xe679;</i> 批量置顶</a>
                    <a href="javascript:;" onclick="duty_all_top_down()" class="btn btn-danger radius">
                        <i class="Hui-iconfont">&#xe631;</i> 批量取消置顶</a>
                    <a href="javascript:;" onclick="duty_all_status_up()" class="btn btn-success radius">
                        <i class="Hui-iconfont">&#xe603;</i> 批量上线</a>
                    <a href="javascript:;" onclick="duty_all_status_down()" class="btn btn-danger radius">
                        <i class="Hui-iconfont">&#xe66b;</i> 批量下线</a>
                </span>
            </div>
            <div class="mt-20">
                <table class="table table-border table-bordered table-bg table-hover table-sort">
                    <thead>
                        <tr class="text-c">
                            <th width="20px">
                                <input type="checkbox" value="" name="allcheck">
                            </th>
                            <th width="40px">ID</th>
                            <th width="100px">缩略图</th>
                            <th width="20%">文章标题</th>
                            <th width="120px">更新日期</th>
                            <th width="80px">栏目</th>
                            <th width="60px">发布人</th>
                            <th width="10%">状态</th>
                            <th width="40px">审核</th>
                            <th width="60px">审核员</th>
                            <th width="120px">审核时间</th>
                            <th width="40px">点击量</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        {foreach $data as $val}
                        <tr class="text-c va-m" style="height:80px;">
                            <td>
                                <input type="checkbox" value="{$val.id}" name="checkbox[]">
                            </td>
                            <td>{$val.id}</td>
                            <td>
                                <img width="60" class="product-thumb" src="{$val.thumb}">
                            </td>
                            <td class="text-l">
                                <a href="javascript:void(0);" style="text-decoration:none" title="浏览">{$val.title}</a>
                            </td>
                            <td class="text-c">{$val.pubtime|date="Y-m-d H:i:s",###}</td>
                            <td class="text-c">{$val.cid|model('category')->getCateName}</td>
                            <td class="text-c">{$val.userid|model('admin_user')->getUsername}</td>
                            <td class="td-status">
                                {eq name='val.top' value='1'}
                                <a href="javascript:void(0);" title="取消置顶" onClick="top_stat('down',this,'{$val.id}')" class="top">
                                    <span class="label label-success radius">置&nbsp;&nbsp;顶</span>
                                </a>
                                {else/}
                                <a href="javascript:void(0);" title="置顶" onClick="top_stat('up',this,'{$val.id}')" class="top">
                                    <span class="label label-default radius">未置顶</span>
                                </a>
                                {/eq} {eq name="val.status" value="1"}
                                <a href="javascript:void(0);" title="下线" onClick="status('down',this,'{$val.id}')" class="status">
                                    <span class="label label-success radius" style="margin-left: 10%">正常</span>
                                </a>
                                {else/}
                                <a href="javascript:void(0);" title="上线" onClick="status('up',this,'{$val.id}')" class="status">
                                    <span class="label label-default radius" style="margin-left: 10%">下线</span>
                                </a>
                                {/eq}
                            </td>
                            {switch name="val.post"} {case value="1"}
                            <td class="td-duty">
                                <a href="javascript:void(0);" title="撤销审核" onClick="dutyDown(this,'{$val.id}')">
                                    <span class="label label-success radius">已过审</span>
                                </a>
                            </td>
                            <td class="td-dutyadmin">{$val.dutyadmin}</td>
                            <td class="td-time">{$val.dutytime|date="Y-m-d H:i:s",###}</td>
                            {/case} {case value="2"}
                            <td class="td-duty">
                                <a href="javascript:void(0);" title="通过审核" onClick="dutyUp(this,'{$val.id}')">
                                    <span class="label label-danger radius">未通过</span>
                                </a>
                            </td>
                            <td class="td-dutyadmin">{$val.dutyadmin}</td>
                            <td class="td-time">{$val.dutytime|date="Y-m-d H:i:s",###}</td>
                            {/case} {default /}
                            <td class="td-duty">
                                <a href="javascript:void(0);" title="审核文章" onClick="duty(this,'{$val.id}')">
                                    <span class="label label-error radius">未审核</span>
                                </a>
                            </td>
                            <td class="td-dutyadmin"></td>
                            <td class="td-time"></td>
                            {/switch}
                            <td>{$val.clicks}</td>
                            <td class="td-manage">
                                <a href="javascript:;" title="文章详情" style="text-decoration:none" onClick="layer_show('文章详情','{:url(\'preview\', \'id=\'.$val.id)}')">
                                    <i class="Hui-iconfont">&#xe685;</i>
                                </a>
                                <a href="{:url('edit', 'id='.$val.id)}" title="编辑" style="text-decoration:none" class="ml-10">
                                    <i class="Hui-iconfont">&#xe6df;</i>
                                </a>
                                <a href="javascript:;" title="删除" style="text-decoration:none" class="ml-10" onClick="del(this,'{$val.id}')">
                                    <i class="Hui-iconfont">&#xe6e2;</i>
                                </a>
                            </td>
                        </tr>
                        {/foreach}
                    </tbody>
                </table>
            </div>
            <div class="cl pd-5 bg-1 bk-gray mt-20 ">
                <span class="l">共
                    <strong>{$counts}</strong> 篇, {$pages} 页 </span>
                <span class="r">
                    {$data->render()}
                </span>
            </div>
        </div>
    </div>
</div>

<!-- 请在下方写此页面业务相关的脚本 -->
<script type="text/javascript">
    //条件删选: 置顶 /上线 /审核
    $(".btn").click(function () {
        var input = $(this).children('label').children('input');
        if (input.attr('disabled') == null) {
            $(input).attr('disabled', true);
            $(this).removeClass();
            $(this).addClass('btn btn-default radius');
        } else {
            $(input).removeAttr('disabled');
            $(this).removeClass();
            $(this).addClass('btn btn-success radius');
        }
    })

    /* 文章-置顶 */
    function top_stat(action, obj, id) {
        var value = 2;
        var title = '置顶';
        var status = '非置顶';
        var color = 'default';
        if (action == "up") {
            var value = 1;
            var title = '取消置顶';
            var status = '置&nbsp;&nbsp;&nbsp;顶';
            var color = 'success';
            action = 'down';
        } else {
            action = 'up';
        }

        var text = "<a href=\"javascript:void(0);\" title='" + title + "' onClick=\"top_stat('" + action + "',this," +
            id +
            ")\">";
        text += '<span class="label label-' + color + ' radius" style="margin-left: 10%">' + status + '</span>';
        text += '</a>';

        $.post('{:url("top")}', {
            'id': id,
            'value': value
        }, function (data) {
            if (data.code == 2) {
                $(obj).after(text);
                $(obj).remove();
                layer.msg(data.msg, {
                    icon: 6,
                    time: 1000
                });
            } else {
                layer.msg(data.msg, {
                    icon: 5,
                    time: 1000
                });
            }
        }, 'json');
    }
    /* 批量置顶 or 取消 */
    function duty_all_top_up() {
        var checkbox = $('.text-c input[name="checkbox[]"]');

        if (checkboxtest(checkbox) == false) {
            return false;
        }

        checkbox.each(function (x) {
            if (this.checked) {
                var obj = $(this).parents('tr').find('.td-status').children('a.top');
                var id = $(this).val();
                top_stat('up', obj, id);
            }
        });
    }

    function duty_all_top_down() {
        var checkbox = $('.text-c input[name="checkbox[]"]');

        if (checkboxtest(checkbox) == false) {
            return false;
        }

        checkbox.each(function (x) {
            if (this.checked) {
                var obj = $(this).parents('tr').find('.td-status').children('a.top');
                var id = $(this).val();
                top_stat('down', obj, id);
            }
        });
    }


    /* 上线 or 下线 */
    function status(action, obj, id) {
        var value = 2;
        var title = '上线';
        var status = '下线';
        var color = 'default';
        if (action == 'up') {
            value = 1;
            action = 'down';
            title = '下线';
            status = '正常';
            color = 'success';
        } else {
            action = 'up';
        }

        var text = "<a href=\"javascript:void(0);\" title='" + title + "' onClick=\"status('" + action + "',this," + id +
            ")\">";
        text += '<span class="label label-' + color + ' radius" style="margin-left: 10%">' + status + '</span>';
        text += '</a>';

        $.post('status', {
            'id': id,
            'value': value
        }, function (data) {
            if (data.code == 2) {
                $(obj).after(text);
                $(obj).remove();
                layer.msg(data.msg, {
                    icon: 6,
                    time: 1000
                });
            } else {
                layer.msg(data.msg, {
                    icon: 5,
                    time: 1000
                });
            }
        }, 'json');
    }
    /* 批量置顶 or 取消 */
    function duty_all_status_up() {
        var checkbox = $('.text-c input[name="checkbox[]"]');

        if (checkboxtest(checkbox) == false) {
            return false;
        }
        checkbox.each(function (x) {
            if (this.checked) {
                var obj = $(this).parents('tr').find('.td-status').children('a.status');
                var id = $(this).val();
                status('up', obj, id);
            }
        });
    }

    function duty_all_status_down() {
        var checkbox = $('.text-c input[name="checkbox[]"]');

        if (checkboxtest(checkbox) == false) {
            return false;
        }
        checkbox.each(function (x) {
            if (this.checked) {
                var obj = $(this).parents('tr').find('.td-status').children('a.status');
                var id = $(this).val();
                status('down', obj, id);
            }
        });
    }


    /*文章-审核*/
    function duty(obj, id) {
        layer.confirm('审核文章？', {
                btn: ['通过', '不通过', '取消'],
                shade: false
            },
            function () {
                do_duty('pass', obj, id);
                // pass(obj, id);
            },
            function () {
                do_duty('reject', obj, id)
                // reject(obj, id);
            },
            function () {
                return false;
            }
        );
    }

    function do_duty(action, obj, id) {
        var post = 0;
        if (action == 'pass') {
            post = 1;
        } else {
            post = 2;
        }
        $.post('duty', {
            'id': id,
            'post': post
        }, function (data) {
            if (data.code == 2) {
                console.log('test');
                $(obj).parents("tr").find(".td-dutyadmin").html(data.dutyadmin);
                $(obj).parents("tr").find(".td-time").html(data.time);
                if (action == 'pass') {
                    $(obj).parents("tr").find(".td-duty").html(
                        '<a href="javascript:void(0);" title="撤销审核" onClick="dutyDown(this,' + id +
                        ')" ><span class="label label-success radius">已过审</span></a>');
                } else {
                    $(obj).parents("tr").find(".td-duty").html(
                        '<a href="javascript:void(0);" title="通过审核" onClick="dutyUp(this,' + id +
                        ')" ><span class="label label-danger radius">未通过</span></a>');
                }
                $(obj).remove();
                layer.msg(data.msg, {
                    icon: 6,
                    time: 1000
                });
            } else {
                layer.msg(data.msg, {
                    icon: 5,
                    time: 1000
                });
            }
        }, 'json');
    }

    function dutyUp(obj, id) {
        layer.confirm('确认通过审核？', function (index) {
            do_duty('pass', obj, id);
        });
    }

    function dutyDown(obj, id) {
        layer.confirm('确认撤销审核？', function (index) {
            do_duty('reject', obj, id)
        });
    }

    /*文章-批量审核通过 / 驳回 */
    function duty_all_pass() {
        layer.confirm('确认通过审核？', function (index) {
            var checkbox = $('.text-c input[name="checkbox[]"]');
            checkbox.each(function (x) {
                if (this.checked) {
                    var obj = $(this).parents('tr').find('.td-duty').children('a');
                    var id = $(this).val();
                    do_duty('pass', obj, id);
                }
            })
        });
    }

    function duty_all_reject() {
        layer.confirm('确认驳回审核？', function (index) {
            var checkbox = $('.text-c input[name="checkbox[]"]');
            checkbox.each(function (x) {
                if (this.checked) {
                    var obj = $(this).parents('tr').find('.td-duty').children('a');
                    var id = $(this).val();
                    do_duty('reject', obj, id);
                }
            })
        });
    }

    /* 检查多选是否为空 */
    function checkboxtest(boxes) {
        var ids = new Array();
        boxes.each(function (x) {
            if (this.checked)
                ids.push(this.value);
        })

        var length = ids.length;

        if (length != 0) {
            return true;
        }
        layer.msg('请选择要删除的选项', {
            icon: 5,
            time: 1000
        });

        return false;
    }

    /*点击展开子栏目*/
    $(function () {
        $(".category").click(function () {
            var cid = $(this).data('cid');
            var status = $(this).data('status');

            if (status == 1) {
                $(".level_" + cid).css('display', 'none');
                $(".top_" + cid).css('display', 'none');
                $(this).children('i').html('&#xe698');
                $(this).data('status', 0);
                $(".level_" + cid).children('label').children('a').data('status', 0);
                return false;
            }
            $(".level_" + cid).css('display', 'block');
            $(this).children('i').html('&#xe69a');
            $(this).data('status', 1);

            return false;
        })
    });

    /*展开所有栏目*/
    function load_all() {
        $('.son').toggle();
        $('.grandson').toggle();
    }
</script>
<!--/请在上方写此页面业务相关的脚本-->